home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Animator (RU).ifs < prev    next >
Encoding:
Text File  |  2004-10-26  |  11.8 KB  |  389 lines

  1. // GETINFO SCRIPTING
  2. // Imports info from Animator.ru
  3.  
  4. (***************************************************
  5.  *  Movie information import script for:           *
  6.  *    Animator Russian,                            *
  7.  *    http://www.animator.ru/                      *
  8.  *                                                 *
  9.  *  (c) 2004 Serguei Tarassov                      *
  10.  *  http://www.arbinada.com                        *
  11.  *                                                 *
  12.  *  Last update:                                   *
  13.  *  - 25.10.2004                                   *
  14.  *                                                 *
  15.  *  Known issues:                                  *
  16.  *  - none                                         *
  17.  *                                                 *
  18.  *  For use with Ant Movie Catalog 3.4.0           *
  19.  *  www.antp.be/software/moviecatalog              *
  20.  *                                                 *
  21.  *  This program is free software; you can         *
  22.  *  redistribute it and/or modify it under the     *
  23.  *  terms of the GNU General Public License as     *
  24.  *  published by the Free Software Foundation;     *
  25.  *  either version 2 of the License, or (at your   *
  26.  *  option) any later version.                     *
  27.  ***************************************************)
  28.  
  29. program AnimatorRu;
  30.  
  31. const
  32.   STR_WIN = '└α┴ß┬Γ├π─Σ┼σ╞µ╟τ╚Φ╔Θ╩Ω╦δ╠∞═φ╬ε╧∩╨≡╤±╥≥╙≤╘⌠╒⌡╓÷╫≈╪°┘∙┌·█√▄ⁿ▌²▐■▀ ';
  33.   STR_KOI = '■▐α└ß┴÷╓Σ─σ┼⌠╘π├⌡╒Φ╚Θ╔Ω╩δ╦∞╠φ═ε╬∩╧ ▀≡╨±╤≥╥≤╙µ╞Γ┬ⁿ▄√█τ╟°╪²▌∙┘≈╫·┌';
  34.   STR_ISO = '╨≡╤±╥≥╙≤╘⌠╒⌡╓÷╫≈╪°┘∙┌·█√▄ⁿ▌²▐■▀ α╣ß╕ΓÉπâΣ║σ╛µ│τ┐Φ╝ΘÜΩ£δ₧∞¥φºεó∩ƒ';
  35.   STR_DOS = 'Ç üíéóâúäñàÑåªçºê¿ë⌐è¬ï"î¼ì¡Ä«Å»Éα''ß''ΓôπöΣòσûµùτÿΦÖΘÜΩ¢δ£∞¥φ₧εƒ∩';
  36.  
  37. const
  38.   DEBUG_MODE = false;
  39.   DEBUG_FOUND_FILMS_FILENAME = 'Animator_found_results.htm';
  40.   DEBUG_FILM_FILENAME        = 'Animator_film.htm';
  41.   
  42. const
  43.   BaseAddress = 'http://www.animator.ru/';
  44.   BaseAddressFilm = BaseAddress + 'db/';
  45.   
  46. var
  47.   MovieName: string;
  48.  
  49. { Some utils functions }
  50. function KOIToWin(Source: string): string;
  51. var
  52.   i: integer;
  53.   s: string;
  54.   c: char;
  55.   chars: array of char;
  56. begin
  57.   Result := '';
  58.   SetArrayLength(chars, 256);
  59.   for i := 0 to 255 do
  60.     chars[i] := chr(i);
  61.   for i := 1 to length(STR_WIN) do
  62.     chars[ord(copy(STR_WIN, i, 1))] := copy(STR_KOI, i, 1);
  63.   for i := 1 to Length(Source) do
  64.     Result := Result + chars[ord(copy(Source, i, 1))];
  65. end;
  66.  
  67. function WinToKOI(Source: string): string;
  68. var
  69.   i: integer;
  70.   s: string;
  71.   c: char;
  72.   chars: array of char;
  73. begin
  74.   Result := '';
  75.   SetArrayLength(chars, 256);
  76.   for i := 0 to 255 do
  77.     chars[i] := chr(i);
  78.   for i := 1 to length(STR_WIN) do
  79.     chars[ord(copy(STR_KOI, i, 1))] := copy(STR_WIN, i, 1);
  80.   for i := 1 to Length(Source) do
  81.     Result := Result + chars[ord(copy(Source, i, 1))];
  82. end;
  83.  
  84.  
  85. procedure DebugOutput(Value: string);
  86. begin
  87.   if DEBUG_MODE then
  88.     Input('Watch', 'Value', Value);
  89. end;
  90.  
  91. procedure DebugOutputFile(FileName: string; FileText: string);
  92. var
  93.   Log: TStringList;
  94. begin
  95.   if DEBUG_MODE then begin
  96.     Log := TStringList.Create;
  97.     Log.Text := FileText;
  98.     Log.SaveToFile(FileName);
  99.     Log.Free;
  100.   end;
  101. end;
  102.  
  103. procedure ClearString(var Value: string);
  104. begin
  105.   HTMLRemoveTags(Value);
  106.   HTMLDecode(Value);
  107.   Value := StringReplace(Value, #13, '');
  108.   Value := StringReplace(Value, #10, '');
  109.   Value := trim(Value);
  110. end;
  111.  
  112. procedure ClearText(var Value: string);
  113. var
  114.   s: string;
  115. begin
  116.   if length(Value) < 2 then exit;
  117.   Value := trim(Value);
  118.   s := copy(Value, 2, length(Value));
  119.   s := StringReplace(s, '<br>', #13#10);
  120.   s := StringReplace(s, '<BR>', #13#10);
  121.   s := StringReplace(s, '<p>', #13#10#13#10);
  122.   s := StringReplace(s, '<p>', #13#10#13#10);
  123.   Value := copy(Value, 1, 1) + s;
  124.   HTMLRemoveTags(Value);
  125.   HTMLDecode(Value);
  126.   Value := trim(Value);
  127. end;
  128.  
  129. procedure RemoveLastDot(var Value: string);
  130. begin
  131.   if length(Value) > 1 then
  132.     if copy(Value, length(Value), 1) = '.' then begin
  133.       Value := copy(Value, 1, length(Value) - 1);
  134.     end;
  135. end;
  136.  
  137. procedure TrimQuotes(var Value: string);
  138. var
  139.   c: char;
  140. begin
  141.   Value := trim(Value);
  142.   c := copy(Value, 1, 1);
  143.   if (c = '''') or (c = '"') or (c = '½') or (c = '<') then
  144.     Value := copy(Value, 2, length(Value));
  145.   c := copy(Value, length(Value), 1);
  146.   if (c = '''') or (c = '"') or (c = '╗') or (c = '>') then
  147.     Value := copy(Value, 1, length(Value) - 1);
  148. end;
  149.  
  150.  
  151.  
  152. { Pages parsing }
  153.  
  154. const
  155.   FoundLabel = '═αΘΣσφε ';
  156.   NothingFoundLabel = '═Φ≈σπε φσ φαΘΣσφε';
  157.   FoundMovieTitleRef = 'href="index.phtml?p=show_film&fid=';
  158.   FoundMovieYearLabel = '<td';
  159.  
  160. //procedure AnalyzeFoundFilmsPage(URL: string; Params: string);
  161. procedure AnalyzeFoundFilmsPage(URL: string);
  162. var
  163.   Page: TStringList;
  164.     FoundTable, SelectedURL: string;
  165.     pos1, pos2: integer;
  166. begin
  167.   PickTreeClear;
  168.   Page := TStringList.Create;
  169. //  Page.Text := PostPage(URL, Params);
  170.   Page.Text := KOIToWin(GetPage(URL));
  171.   DebugOutputFile(DEBUG_FOUND_FILMS_FILENAME, Page.Text);
  172.   if pos(NothingFoundLabel, Page.Text) = 0 then begin
  173.     pos1 := pos(FoundLabel, Page.Text);
  174.     if pos1 <> 0 then begin
  175.       FoundTable := copy(Page.Text, pos1, length(Page.Text));
  176.       //DebugOutput(FoundTable);
  177.       FoundTable := copy(FoundTable, 1, pos('</td', FoundTable) - 1);
  178.       if pos(FoundMovieTitleRef, FoundTable) > 0 then
  179.         AddFoundMoviesTitles(FoundTable);
  180.     end;
  181.   end;
  182.   Page.Free;
  183.     if PickTreeExec(SelectedURL) then
  184.     AnalyzeFilmPage(SelectedURL);
  185. end;
  186.  
  187.  
  188. procedure AddFoundMoviesTitles(Table: string);
  189. var
  190.     CurName, CurURL, s: string;
  191.     pos2, len: integer;
  192. begin
  193.      PickTreeAdd('Cartoons', '');
  194.   len := length(Table);
  195.   while pos(FoundMovieTitleRef, Table) > 0 do begin
  196.     Table := copy(Table, pos(FoundMovieTitleRef, Table) + length('href="'), len);
  197.     pos2 := pos('"', Table);
  198.     CurURL := copy(Table, 1, pos2 - 1);
  199.     //DebugOutput(CurURL);
  200.     Table := copy(Table, pos('>', Table) + 1, len);
  201.     pos2 := pos('<', Table);
  202.     CurName := copy(Table, 1, pos2 - 1);
  203.     ClearString(CurName);
  204.     Table := copy(Table, pos2 + 1, len);
  205.     //DebugOutput(CurName);
  206.     PickTreeAdd(CurName, BaseAddressFilm + CurURL);
  207.   end;
  208. end;
  209.  
  210.  
  211. const
  212.   FilmImageAnchor = 'src="../film_img';
  213.   FilmTitleAnchor = 'class="FilmName">';
  214.   FilmStudioAnchor = '<span';
  215.   FilmActorsAnchor = 'ετΓ≤≈ΦΓαδΦ';
  216.   FilmDirectorAnchor = '≡σµΦ±±σ≡';
  217.   FilmContentAnchor = 'FilmComments';
  218.  
  219. procedure AnalyzeFilmPage(SelectedURL: string);
  220. var
  221.   Page: TStringList;
  222.     Content, Year, Value, FilmType, Actors, Creators: string;
  223.     pos1, pos2, len: integer;
  224. begin
  225.   Page := TStringList.Create;
  226.   Page.Text := KOIToWin(GetPage(SelectedURL));
  227.   DebugOutputFile(DEBUG_FILM_FILENAME, Page.Text);
  228.   
  229.   SetField(fieldURL, SelectedURL)
  230.  
  231.   len := length(Page.Text);
  232.   Content := Page.Text;
  233.   
  234.   // Picture
  235.   pos1 := pos(FilmImageAnchor, Content);
  236.   if pos1 > 0 then begin
  237.     Content := copy(Content, pos1 + length('src="../'), len);
  238.     pos2 := pos('"', Content);
  239.     Value := BaseAddress + copy(Content, 1, pos2 - 1);
  240.     if Input('═αΘΣσφα Ωα≡≥ΦφΩα Ω ⌠Φδⁿ∞≤', '╟απ≡≤τΦ≥ⁿ Ωα≡≥ΦφΩ≤ ?'#13#10'URL:', Value) then
  241.       GetPicture(Value, False); // False = do not store picture externally
  242.   end;
  243.  
  244.   // Film title
  245.   pos1 := pos(FilmTitleAnchor, Content);
  246.   Content := copy(Content, pos1 + length(FilmTitleAnchor), len);
  247.   pos2 := pos('<', Content);
  248.   Value := copy(Content, 1, pos2 - 1);
  249.   ClearString(Value);
  250.   TrimQuotes(Value);
  251.   Value := AnsiMixedCase(AnsiLowerCase(Value), ' -.');
  252.   SetField(fieldOriginalTitle, Value);
  253.   SetField(fieldTranslatedTitle, Value);
  254.   Content := copy(Content, pos2, len);
  255.  
  256.   // Type and length
  257.   FilmType := '╨Φ±εΓαφφ√Θ';
  258.   // skip 2 <td>
  259.   Content := copy(Content, pos('<td', Content) + 1, len);
  260.   Content := copy(Content, pos('>', Content) + 1, len);
  261.   Content := copy(Content, pos('<td', Content) + 1, len);
  262.   Content := copy(Content, pos('>', Content) + 1, len);
  263.   pos2 := pos('<td', Content);
  264.   if pos2 < pos(FilmStudioAnchor, Content) then begin
  265.     Content := copy(Content, pos2, len);
  266.     pos2 := pos('</td', Content);
  267.     Value := copy(Content, 1, pos2 - 1);
  268.     HTMLRemoveTags(Value);
  269.     pos1 := pos(',', Value);
  270.     if pos1 > 0 then begin
  271.       FilmType := copy(Value, 1, pos1 - 1);
  272.       ClearString(FilmType);
  273.       Value := copy(Value, pos1 + 1, length(Value));
  274.       if pos('.', Value) > 0 then
  275.         Value := copy(Value, 1, pos('.', Value) - 1);
  276.       ClearString(Value);
  277.       SetField(fieldLength, Value);
  278.     end;
  279.     Content := copy(Content, pos2, len);
  280.     Content := copy(Content, pos('>', Content) + 1, len);
  281.   end;
  282.  
  283.   // Studio
  284.   Content := copy(Content, pos(FilmStudioAnchor, Content), len);
  285.   Content := copy(Content, pos('>', Content) + 1, len);
  286.   pos2 := pos('<', Content);
  287.   Value := copy(Content, 1, pos2 - 1);
  288.   ClearString(Value);
  289.   SetField(fieldSource, Value);
  290.   Content := copy(Content, pos2, len);
  291.   Content := copy(Content, pos('>', Content) + 1, len);
  292.  
  293.   // Year
  294.   Content := copy(Content, pos(',', Content) + 1, len);
  295.   pos2 := pos('π.', Content);
  296.   if pos2 = 0 then
  297.     pos2 := pos('<', Content);
  298.   Value := copy(Content, 1, pos2 - 1);
  299.   ClearString(Value);
  300.   SetField(fieldYear, Value);
  301.   Year := Value;
  302.   Content := copy(Content, pos2, len);
  303.   Content := copy(Content, pos('>', Content) + 1, len);
  304.   
  305.   // Country
  306.   Value := '╤╤╤╨';
  307.   if Year <> '' then
  308.     if StrToInt(Year, 0) >= 1992 then
  309.       Value := '╨ε±±Φ ';
  310.   SetField(fieldCountry, Value);
  311.  
  312.   // Category
  313.   SetField(fieldCategory, '└φΦ∞α÷Φεφφ√Θ');
  314.   
  315.   // Content
  316.   pos2 := pos(FilmContentAnchor, Content);
  317.   if pos2 > 0 then begin
  318.     Content := copy(Content, pos2, len);
  319.     Content := copy(Content, pos('>', Content) + 1, len);
  320.     pos2 := pos('</table', Content);
  321.     Value := copy(Content, 1, pos2 - 1);
  322.     ClearText(Value);
  323.     Value := StringReplace(Value, #13#10#13#10, #13#10);
  324.     SetField(fieldDescription, Value);
  325.     Content := copy(Content, pos2, len);
  326.   end;
  327.  
  328.   // Director
  329.   pos2 := pos(FilmDirectorAnchor, Content);
  330.   if pos2 > 0 then begin
  331.     Content := copy(Content, pos2, len);
  332.     Content := copy(Content, pos('>', Content) + 1, len);
  333.     pos2 := pos('</span', Content);
  334.     Value := copy(Content, 1, pos2 - 1);
  335.     ClearString(Value);
  336.     SetField(fieldDirector, Value);
  337.     Content := copy(Content, pos2, len);
  338.   end;
  339.   
  340.   // Creators and actors
  341.   pos2 := pos('</table', Content);
  342.   Creators := copy(Content, 1, pos2 - 1);
  343.   Content := copy(Content, pos2, len);
  344.   Actors := Creators;
  345.   pos2 := pos(FilmActorsAnchor, Actors);
  346.   if pos2 > 0 then begin
  347.     Actors := copy(Actors, pos2, len);
  348.     Actors := copy(Actors, pos('>', Actors) + 1, len);
  349.     pos2 := pos('</tr', Actors);
  350.     Actors := copy(Actors, 1, pos2 - 1);
  351.     ClearText(Actors);
  352.     Value := Actors;
  353.     ClearString(Value);
  354.     SetField(fieldActors, Value);
  355.   end;
  356.   Creators := StringReplace(Creators,
  357.                             '</td><td class="PersonsList',
  358.                             ': </td><td class="PersonsList');
  359.   ClearText(Creators);
  360.   Creators := StringReplace(Creators, Actors, '');
  361.   Creators := StringReplace(Creators, '≡εδΦ ετΓ≤≈ΦΓαδΦ: ', '');
  362.   Creators := FilmType + #13#10 + Creators;
  363.   Creators := StringReplace(Creators, #13#10#13#10, #13#10);
  364.   SetField(fieldComments, Creators);
  365.   
  366.   Page.Free;
  367.   DisplayResults;
  368. end;
  369.  
  370. begin
  371.   if CheckVersion(3, 4, 0) then
  372.   begin
  373.     MovieName := GetField(fieldOriginalTitle);
  374.     if MovieName = '' then
  375.       MovieName := GetField(fieldTranslatedTitle);
  376.  
  377.     if Input('Import from Animator',
  378.              'Enter the title of the movie:', MovieName) then
  379.     begin
  380.       MovieName := WinToKOI(MovieName);
  381.       AnalyzeFoundFilmsPage(BaseAddress +
  382.         'db/index.phtml?cPage=&p=search&SearchMask=1&text=' +
  383.         UrlEncode(MovieName));
  384.     end;
  385.   end else
  386.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  387. end.
  388.  
  389.